package com.secsbrain.development.web.utils;

import org.apache.commons.lang3.StringUtils;

public class BranchUtils {

    /** 线上Release分支名称 */
    public static final String RELEASE_BRANCH="release";

    /** 线上Bugfix分支名称 */
    public static final String BUGFIX_BRANCH="bugfix";

    /** 集成测试分支名称 */
    public static final String SIT_BRANCH="trunk";

    /** 开发分支名称 */
    public static final String DEV_BRANCH="develop";

    /**
     * 校验分支名称
     * @param envName    环境名称
     * @param branchName 分支名称
     * @return
     */
    public static String checkBranchName(String envName, String branchName){
        if(envName.contains("dev")){
            if(!(branchName.contains(DEV_BRANCH)||branchName.contains(SIT_BRANCH)||
                    branchName.contains(BUGFIX_BRANCH)||branchName.contains(RELEASE_BRANCH))){
                return "dev环境的发布分支只能是"+DEV_BRANCH+"、"+SIT_BRANCH+"、"+BUGFIX_BRANCH+"、"+RELEASE_BRANCH+"的一个";
            }
        }else if(envName.contains("sit")){
            if(!(branchName.contains(SIT_BRANCH) || branchName.contains(BUGFIX_BRANCH)||branchName.contains(RELEASE_BRANCH))){
                return "sit环境的发布分支只能是"+SIT_BRANCH+"、"+BUGFIX_BRANCH+"、"+RELEASE_BRANCH+"的一个";
            }
        }else if(envName.contains("pre")||envName.contains("prod")){
            if(!(branchName.contains(BUGFIX_BRANCH)||branchName.contains(RELEASE_BRANCH))){
                return "线上环境的发布分支只能是" + BUGFIX_BRANCH+"或者"+RELEASE_BRANCH;
            }
        }

        return null;
    }

}